// $Id: BaseOperations.java 2 2012-02-07 16:21:11Z diblikp@gmail.com $
package cz.pd.hamrsport.utils;

import com.thoughtworks.selenium.Selenium;
import org.joda.time.DateTime;
import org.joda.time.DateTimeUtils;

/**
 * 
 * @author diblik
 * @version $Revision: 2 $
 */
public class BaseOperations {

  private static Selenium selenium;


  public static void startSeleniumServer() {
  }
  public static void waitToLoadElement(String elementID) {
    selenium.waitForCondition(
        "selenium.browserbot.getCurrentWindow().document.getElementById('" + elementID + "')", "10000");
  }

  public static void login(String name, String passwd) {
    selenium.open("/");
    selenium.click("login");
    selenium.waitForPageToLoad("30000");
    selenium.type("loginForm_os_password", passwd);
    selenium.type("loginForm_os_username", name);
    selenium.click("//form[@id='loginForm']/div/div[7]/div/input[2]");
    waitToLoadElement("viewProject:OKCMODULVCSTAG");
  }

  public static void fakeWorking(int seconds) {
    DateTime akCas = new DateTime(DateTimeUtils.currentTimeMillis());
    akCas = akCas.plusSeconds(seconds);
    while (akCas.isAfter(new DateTime(DateTimeUtils.currentTimeMillis())));
  }

  public static void setSelenium(Selenium selenium) {
    BaseOperations.selenium = selenium;
  }

//  public static Project[] concat(Project[] A, Project[] B) {
//    Project[] C = new Project[A.length + B.length];
//    System.arraycopy(A, 0, C, 0, A.length);
//    System.arraycopy(B, 0, C, A.length, B.length);
//
//    return C;
//  }
//
//  public static Project[] concat(Project[]... projects) {
//    int size = 0;
//    for (Project[] projects1 : projects) {
//      size += projects1.length;
//    }
//
//    Project[] finalProj = new Project[size];
//    System.arraycopy(projects[0], 0, finalProj, 0, projects[0].length);
//    for (int i = 1; i < projects.length; i++) {
//      System.arraycopy(projects[i], 0, finalProj, projects[i - 1].length, projects[i].length);
//    }
//
//    return finalProj;
//  }
//
//  public static List<Project> toList(Project[] projects) {
//    List<Project> list = new ArrayList<Project>();
//    for (Project project : projects) {
//      list.add(project);
//    }
//
//    return list;
//  }
//
//  public static Project[] toPole(List<Project> projects) {
//    return projects.toArray(new Project[projects.size()]);
//  }
//
//  public static Project[] toPole(Project... projects) {
//    return projects;
//  }
//
//  public static List<Project> removeFromList(List<Project> list, Comparable<Project> comparable) {
//    List<Project> projects = new ArrayList<Project>(list);
//    for (Iterator<Project> it = projects.iterator(); it.hasNext();) {
//      Project project = it.next();
//      if (comparable.compareTo(project) == 1) {
//        it.remove();
//      }
//    }
//    return projects;
//  }
}
